package com.leetcode.weekly.contest.no233th;

/**
 * @author 覃国强
 * @date 2021-03-21 10:45
 */
public class A01_最大升序子数组和 {

  public static void main(String[] args) {
    Solution solution = new Solution();

    int[] nums = {12,17,15,13,10,11,12};
    int sum = solution.maxAscendingSum(nums);
    System.out.println(sum);


  }


  static
  class Solution {
    public int maxAscendingSum(int[] nums) {
      if (nums.length == 1) {
        return nums[0];
      }
      int max = nums[0];
      int preMax = nums[0];
      for (int i = 1; i < nums.length; ++i) {
        if (nums[i - 1] < nums[i]) {
          preMax += nums[i];
        } else {
          preMax = nums[i];
        }
        max = Math.max(preMax, max);
      }

      return max;
    }
  }

}
